function getIMG(imgName) {
    return safari.extension.baseURI + "img/" + imgName;
}

function isUrl(text) {
    var regex = /^(https?|ftp|gopher|telnet|file|notes|ms-help):\/\//;
    return regex.test(text);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function decidePos(ev) {
    var zoom_factor=zoomLevel*detectZoom();
    var left_margin=Math.max(this.screenX, 0);
    var right_margin=Math.min(this.outerWidth+this.screenX, screen.width);
    var bottom_margin=Math.min(this.outerHeight+this.screenY, screen.height);   
 
    var detX=right_margin-ev.screenX;
    var detY=bottom_margin-ev.screenY;

    if(ev.screenX-Xoffset*zoom_factor<left_margin) engines.style.posLeft=(ev.pageX+left_margin-ev.screenX)/zoom_factor;
    else if((Xoffset+2)*zoom_factor>detX)
        engines.style.posLeft=(ev.pageX+detX-16)/zoom_factor-2*Xoffset-4;
    else
        engines.style.posLeft=ev.pageX/zoom_factor-Xoffset;
    
    if((Yoffset+48+2)*zoom_factor>detY)
        engines.style.posTop=ev.pageY/zoom_factor-Yoffset-48;
    else
        engines.style.posTop=ev.pageY/zoom_factor+Yoffset;
}

